package com.lzw.breezeNovel.WebAdmin.controller;


import com.lzw.breezeNovel.WebAdmin.service.UserService;
import com.lzw.breezeNovel.WebAdmin.vo.StatisticsVo;
import com.lzw.breezeNovel.WebAdmin.vo.UserInfoVo;
import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.pojo.user.UserInfo;
import com.lzw.breezeNovel.model.entity.query.novel.NovelPage;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * 用户controller
 */
@RestController
@RequestMapping("/admin")
@SuppressWarnings("all")
public class UserController {

    /**
     * 注入service
     */
    @Resource
    private UserService userService;


    /**
     * 新增用户
     */
    @PostMapping("/add")
    public Result addUser(@RequestBody UserInfo readUser) {
        userService.addUser(readUser);
        return Result.ok();
    }

    /**
     * 获取所有的用户信息
     */
    @PostMapping("/list")
    public Result<PaginationResultQuery<UserInfoVo>> list(@RequestBody NovelPage page) {
        //获取所有的用户信息
        PaginationResultQuery<UserInfoVo> list = userService.list(page);
        return Result.ok(list);
    }

    /**
     * 修改用户
     */
    @PostMapping("/update")
    public Result update(@RequestBody UserInfo readUser) {
        userService.update(readUser);
        return Result.ok();
    }

    /**
     * 删除用户
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody UserInfo readUser) {
        userService.delete(readUser);
        return Result.ok();
    }

    /**
     * 批量删除用户
     */
    @DeleteMapping("/deleteBatch/{ids}")
    public Result deleteBatch(@PathVariable("ids") Long[] ids) {
        userService.deleteBatch(ids);
        return Result.ok();
    }

    /**
     * 统计用户信息
     */
    @GetMapping("/statistics")
    public Result<StatisticsVo> count() {
        StatisticsVo statisticsVo = userService.getStatistic();
        return Result.ok(statisticsVo);
    }



}
